package dobest.ray.com.jiongjiong.activity.action.selftest;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import dobest.ray.com.jiongjiong.R;
import dobest.ray.com.jiongjiong.activity.BaseActivity;
import dobest.ray.com.jiongjiong.activity.action.selftest.NearVision.NearVisionGuildActivity;
import dobest.ray.com.jiongjiong.utils.ACacheHelper;
import dobest.ray.com.jiongjiong.views.CoustomNoticeDialog;
import dobest.ray.com.jiongjiong.views.NavigationBar;

/**
 * Created by Ray on 2016/3/19.
 * https://github.com/ray0807
 * 视力自测
 */
public class VisionSelfTestChooseActivity extends BaseActivity implements View.OnClickListener {
    private ImageView iv_question_1;
    private ImageView iv_question_2;
    private ImageView iv_question_3;
    private ImageView iv_question_4;
    private RelativeLayout rl_near_vision;//近视力
    private TextView tv_near_vision;


    private RelativeLayout rl_naked_eye;//裸眼视力
    private TextView tv_naked_eye;

    private RelativeLayout rl_correct_vision;//矫正视力
    private TextView tv_correct_vision;


    private RelativeLayout rl_color_vision_test;//色觉测试
    private TextView tv_color_vision_test;

    private CoustomNoticeDialog dialog;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vision_self_test_choose);
        findViews();
        init();
        addListeners();
    }

    @Override
    public void findViews() {
        navi = (NavigationBar) findViewById(R.id.navi);
        navi.setBackListener(R.mipmap.img_back, "");
        navi.setTitle("自测选择");
        navi.setTextRight("调整", this);
        navi.setTextRightColor(getResources().getColor(R.color.white));
        iv_question_1 = (ImageView) findViewById(R.id.iv_question_1);
        iv_question_2 = (ImageView) findViewById(R.id.iv_question_2);
        iv_question_3 = (ImageView) findViewById(R.id.iv_question_3);
        iv_question_4 = (ImageView) findViewById(R.id.iv_question_4);
        rl_near_vision = (RelativeLayout) findViewById(R.id.rl_near_vision);
        rl_naked_eye = (RelativeLayout) findViewById(R.id.rl_naked_eye);
        tv_near_vision = (TextView) findViewById(R.id.tv_near_vision);
        tv_naked_eye = (TextView) findViewById(R.id.tv_naked_eye);
        rl_correct_vision = (RelativeLayout) findViewById(R.id.rl_correct_vision);
        rl_color_vision_test = (RelativeLayout) findViewById(R.id.rl_color_vision_test);
        tv_correct_vision = (TextView) findViewById(R.id.tv_correct_vision);
        tv_color_vision_test = (TextView) findViewById(R.id.tv_color_vision_test);
    }

    @Override
    public void init() {
        dialog = new CoustomNoticeDialog(this, true);
    }

    @Override
    public void addListeners() {
        iv_question_1.setOnClickListener(this);
        iv_question_2.setOnClickListener(this);
        iv_question_3.setOnClickListener(this);
        iv_question_4.setOnClickListener(this);
        rl_near_vision.setOnClickListener(this);
        rl_naked_eye.setOnClickListener(this);
        rl_correct_vision.setOnClickListener(this);
        rl_color_vision_test.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent it = null;
        switch (v.getId()) {
            case R.id.iv_question_1:
                dialog.setTitle("说明");
                dialog.setContent("进行粗浅的眼病排查，通过长期监测可以大致了解用眼疲劳程度的波动");
                dialog.setConfirmListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });
                dialog.show();
                break;
            case R.id.iv_question_2:
                dialog.setTitle("说明");
                dialog.setContent("进行粗浅的视力不良监测");
                dialog.setConfirmListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });
                dialog.show();
                break;
            case R.id.iv_question_3:
                dialog.setTitle("说明");
                dialog.setContent("与矫正处方视力值对比，判断是否需要调整眼镜度数");
                dialog.setConfirmListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });
                dialog.show();
                break;
            case R.id.iv_question_4:
                dialog.setTitle("说明");
                dialog.setContent("用于判断色盲、色弱等情况");
                dialog.setConfirmListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });
                dialog.show();
                break;
            case R.id.ll_text_right:
                it = new Intent(this, MesureCoinActivity.class);
                break;
            case R.id.rl_near_vision:
                if (ACacheHelper.getInstance().getMesurePX(this) <= 0) {
                    showDialog();
                } else {
                    setBtnBg(1);
                    NearVisionGuildActivity.startVisionGuildActivity(this, 0);
                }
                break;
            case R.id.rl_naked_eye:
                if (ACacheHelper.getInstance().getMesurePX(this) <= 0) {
                    showDialog();
                } else {
                    setBtnBg(2);
                    NearVisionGuildActivity.startVisionGuildActivity(this, 1);
                }
                break;
            case R.id.rl_correct_vision:
                if (ACacheHelper.getInstance().getMesurePX(this) <= 0) {
                    showDialog();
                } else {
                    setBtnBg(3);
//                it = new Intent(this, NearVisionGuildActivity.class);
                }
                break;
            case R.id.rl_color_vision_test:
                setBtnBg(4);
//                it = new Intent(this, NearVisionGuildActivity.class);
                break;
        }
        if (it != null) {
            startActivity(it);
        }
    }

    private void setBtnBg(int i) {
        switch (i) {
            case 1:
                rl_near_vision.setBackgroundResource(R.drawable.shape_online_selected_ll);
                tv_near_vision.setTextColor(getResources().getColor(R.color.white));

                rl_naked_eye.setBackgroundResource(R.drawable.shape_online_ll);
                tv_naked_eye.setTextColor(getResources().getColor(R.color.grey));
                rl_correct_vision.setBackgroundResource(R.drawable.shape_online_ll);
                tv_correct_vision.setTextColor(getResources().getColor(R.color.grey));
                rl_color_vision_test.setBackgroundResource(R.drawable.shape_online_ll);
                tv_color_vision_test.setTextColor(getResources().getColor(R.color.grey));
                break;
            case 2:
                rl_naked_eye.setBackgroundResource(R.drawable.shape_online_selected_ll);
                tv_naked_eye.setTextColor(getResources().getColor(R.color.white));

                rl_near_vision.setBackgroundResource(R.drawable.shape_online_ll);
                tv_near_vision.setTextColor(getResources().getColor(R.color.grey));
                rl_correct_vision.setBackgroundResource(R.drawable.shape_online_ll);
                tv_correct_vision.setTextColor(getResources().getColor(R.color.grey));
                rl_color_vision_test.setBackgroundResource(R.drawable.shape_online_ll);
                tv_color_vision_test.setTextColor(getResources().getColor(R.color.grey));
                break;
            case 3:

                rl_correct_vision.setBackgroundResource(R.drawable.shape_online_selected_ll);
                tv_correct_vision.setTextColor(getResources().getColor(R.color.white));

                rl_naked_eye.setBackgroundResource(R.drawable.shape_online_ll);
                tv_naked_eye.setTextColor(getResources().getColor(R.color.grey));
                rl_near_vision.setBackgroundResource(R.drawable.shape_online_ll);
                tv_near_vision.setTextColor(getResources().getColor(R.color.grey));
                rl_color_vision_test.setBackgroundResource(R.drawable.shape_online_ll);
                tv_color_vision_test.setTextColor(getResources().getColor(R.color.grey));

                break;
            case 4:
                rl_color_vision_test.setBackgroundResource(R.drawable.shape_online_selected_ll);
                tv_color_vision_test.setTextColor(getResources().getColor(R.color.white));

                rl_naked_eye.setBackgroundResource(R.drawable.shape_online_ll);
                tv_naked_eye.setTextColor(getResources().getColor(R.color.grey));
                rl_correct_vision.setBackgroundResource(R.drawable.shape_online_ll);
                tv_correct_vision.setTextColor(getResources().getColor(R.color.grey));
                rl_near_vision.setBackgroundResource(R.drawable.shape_online_ll);
                tv_near_vision.setTextColor(getResources().getColor(R.color.grey));
                break;
        }
    }


    private void showDialog() {
        final CoustomNoticeDialog dialog = new CoustomNoticeDialog(this);
        dialog.setTitle("您暂未为设置");
        dialog.setContent("是否进入设置界面");
        dialog.setConfirmListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it1 = new Intent(VisionSelfTestChooseActivity.this, MesureCoinActivity.class);
                VisionSelfTestChooseActivity.this.startActivity(it1);
                dialog.dismiss();
            }
        });
        dialog.show();
    }
}
